

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>ccqw.projDialog &mdash; CCQW 0.1.1 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/sidebar.js"></script>
    <link rel="top" title="CCQW 0.1.1 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for ccqw.projDialog</h1><div class="highlight"><pre>
<span class="c"># -*- coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot; Projection Dialog: a widget to choose Datum / Projection from pyproj</span>

<span class="sd">    :Author:</span>
<span class="sd">      - 20111221-20120313 Roberto Vidmar</span>

<span class="sd">    :Revision:  $Revision: 52 $</span>
<span class="sd">                $Date: 2012-11-12 10:07:15 +0100 (Mon, 12 Nov 2012) $</span>

<span class="sd">    :Copyright: 2011-2012</span>
<span class="sd">                Nicola Creati &lt;ncreati@inogs.it&gt;</span>
<span class="sd">                Roberto Vidmar &lt;rvidmar@inogs.it&gt;</span>

<span class="sd">    :License: MIT/X11 License (see :download:`license.txt</span>
<span class="sd">                               &lt;../../license.txt&gt;`)</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">from</span> <span class="nn">qtCompat</span> <span class="kn">import</span> <span class="n">Qt</span><span class="p">,</span> <span class="n">QtCore</span><span class="p">,</span> <span class="n">QtGui</span>
<span class="n">QCA</span> <span class="o">=</span> <span class="n">QtCore</span><span class="o">.</span><span class="n">QCoreApplication</span>

<span class="kn">from</span> <span class="nn">projMVC</span> <span class="kn">import</span> <span class="p">(</span><span class="n">ProjView</span><span class="p">,</span> <span class="n">ProjModel</span><span class="p">,</span> <span class="n">SaveEPSGDialog</span><span class="p">,</span> <span class="n">DATUMSHIFT_KEYWORD</span><span class="p">,</span>
  <span class="n">GEOIDGRIDS_KEYWORD</span><span class="p">,</span> <span class="n">EXTRA_KEYWORDS</span><span class="p">)</span>

<span class="c">#===============================================================================</span>
<div class="viewcode-block" id="SearchWidget"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.SearchWidget">[docs]</a><span class="k">class</span> <span class="nc">SearchWidget</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QWidget</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; Search for a string in the projection tree.</span>
<span class="sd">      The widget has a button and a QlineEdit field.</span>
<span class="sd">  &quot;&quot;&quot;</span>
<div class="viewcode-block" id="SearchWidget.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.SearchWidget.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new SearchWidget instance.</span>

<span class="sd">      :param parent: parent widget</span>
<span class="sd">      :type parent: QtGui widget</span>
<span class="sd">      :param text: the text to search for</span>
<span class="sd">      :type text: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">SearchWidget</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">searchEditor</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QLineEdit</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchEditor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;SearchWidget&quot;</span><span class="p">,</span>
      <span class="s">&quot;Enter here the string to search for.</span><span class="se">\n</span><span class="s">&quot;</span>
      <span class="s">&quot;This string will be searched through</span><span class="se">\n</span><span class="s">all known coordinate reference &quot;</span>
      <span class="s">&quot;system&quot;</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">defaultText</span> <span class="o">=</span> <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;SearchWidget&quot;</span><span class="p">,</span> <span class="s">&#39;New Search:&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QPushButton</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">defaultText</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span>
      <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;SearchWidget&quot;</span><span class="p">,</span>
      <span class="s">&quot;Click here to search for the string to the right</span><span class="se">\n</span><span class="s">&quot;</span>
      <span class="s">&quot;among all known coordinate reference system&quot;</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">defaultText</span> <span class="o">=</span> <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;SearchWidget&quot;</span><span class="p">,</span> <span class="s">&#39;New Search:&#39;</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span><span class="o">.</span><span class="n">setIcon</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QIcon</span><span class="p">(</span><span class="s">&quot;:/icon_search.png&quot;</span><span class="p">))</span>

    <span class="n">o</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QHBoxLayout</span><span class="p">()</span>
    <span class="n">o</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span><span class="p">)</span>
    <span class="n">o</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">searchEditor</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">setLayout</span><span class="p">(</span><span class="n">o</span><span class="p">)</span>

    <span class="c"># Connect button to search method</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">()</span><span class="o">.</span><span class="n">search</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchEditor</span><span class="o">.</span><span class="n">textChanged</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">onTextChanged</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SearchWidget.onTextChanged"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.SearchWidget.onTextChanged">[docs]</a>  <span class="k">def</span> <span class="nf">onTextChanged</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Update text contained in the search button</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">defaultText</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SearchWidget.text"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.SearchWidget.text">[docs]</a>  <span class="k">def</span> <span class="nf">text</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return text contained in the QLineEdit widget</span>

<span class="sd">      :returns: text contained in the QLineEdit widget</span>
<span class="sd">      :rtype: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">searchEditor</span><span class="o">.</span><span class="n">text</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="SearchWidget.setText"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.SearchWidget.setText">[docs]</a>  <span class="k">def</span> <span class="nf">setText</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Set the text contained in the QLineEdit widget</span>

<span class="sd">      :param text: new text</span>
<span class="sd">      :type text: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchEditor</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SearchWidget.resetBtnText"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.SearchWidget.resetBtnText">[docs]</a>  <span class="k">def</span> <span class="nf">resetBtnText</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Reset the text contained in the Button widget to its default</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">defaultText</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SearchWidget.setBtnText"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.SearchWidget.setBtnText">[docs]</a>  <span class="k">def</span> <span class="nf">setBtnText</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Set the text contained in the Button widget to text</span>

<span class="sd">      :param text: new text</span>
<span class="sd">      :type text: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchBtn</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>

<span class="c">#===============================================================================</span></div></div>
<div class="viewcode-block" id="ProjDialog"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.ProjDialog">[docs]</a><span class="k">class</span> <span class="nc">ProjDialog</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QDialog</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; Projection selection dialog</span>
<span class="sd">  &quot;&quot;&quot;</span>
  <span class="n">WGS84</span> <span class="o">=</span> <span class="s">&#39;+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs&#39;</span>
<div class="viewcode-block" id="ProjDialog.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.ProjDialog.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">proj</span><span class="o">=</span><span class="n">WGS84</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new ProjDialog instance.</span>

<span class="sd">      :param proj: the PROJ.4 string defining the projection</span>
<span class="sd">      :type proj: string</span>
<span class="sd">      :param parent: parent widget</span>
<span class="sd">      :type parent: QtGui widget</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">ProjDialog</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">setWindowTitle</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span> <span class="s">&quot;Datum and Projections&quot;</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">foundProjStr</span> <span class="o">=</span> <span class="bp">None</span>

    <span class="c"># Projections Tree</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">tree</span> <span class="o">=</span> <span class="n">ProjView</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
    <span class="c"># Set the tree model</span>
    <span class="n">model</span> <span class="o">=</span> <span class="n">ProjModel</span><span class="p">()</span>
    <span class="n">model</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">setModel</span><span class="p">(</span><span class="n">model</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">selectionModel</span><span class="p">()</span><span class="o">.</span><span class="n">currentChanged</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">onCurrentChanged</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">setColumnHidden</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">resizeView</span><span class="p">()</span>

    <span class="c"># Current Projection</span>
    <span class="n">currentProj</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QHBoxLayout</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QLabel</span><span class="p">(</span><span class="n">proj</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span>
      <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span> <span class="s">&quot;The current Datum/Projection PROJ.4 string&quot;</span><span class="p">))</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">setTextInteractionFlags</span><span class="p">(</span><span class="n">Qt</span><span class="o">.</span><span class="n">TextBrowserInteraction</span><span class="p">)</span>

    <span class="n">f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">font</span><span class="p">()</span>
    <span class="n">f</span><span class="o">.</span><span class="n">setBold</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">setFont</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">setWordWrap</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">setAlignment</span><span class="p">(</span><span class="n">Qt</span><span class="o">.</span><span class="n">AlignLeft</span><span class="p">)</span>
    <span class="n">currentLabel</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QLabel</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span>
      <span class="s">&quot;Current Projection:  &quot;</span><span class="p">))</span>
    <span class="n">currentLabel</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span>
      <span class="s">&quot;The Datum/Projection in use now&quot;</span><span class="p">))</span>
    <span class="n">currentProj</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="n">currentLabel</span><span class="p">,</span> <span class="n">alignment</span><span class="o">=</span><span class="n">Qt</span><span class="o">.</span><span class="n">AlignTop</span><span class="p">)</span>
    <span class="n">currentProj</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="p">,</span> <span class="n">stretch</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
      <span class="n">alignment</span><span class="o">=</span><span class="n">Qt</span><span class="o">.</span><span class="n">AlignTop</span><span class="p">)</span>

    <span class="c"># Search widget</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span> <span class="o">=</span> <span class="n">SearchWidget</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">proj</span><span class="p">)</span>
    <span class="n">searchGroup</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QGroupBox</span><span class="p">(</span>
      <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span>
      <span class="s">&quot;Search for PROJ.4 (sub)string or EPSG code:&quot;</span><span class="p">))</span>
    <span class="n">searchGroup</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span>
      <span class="s">&quot;You can search for any text through all</span><span class="se">\n</span><span class="s">&quot;</span>
      <span class="s">&quot;known Coordinate Reference Systems</span><span class="se">\n</span><span class="s">and EPSG codes&quot;</span><span class="p">))</span>
    <span class="n">searchGroup</span><span class="o">.</span><span class="n">setStyleSheet</span><span class="p">(</span><span class="s">&quot; background-color: qlineargradient(&quot;</span>
      <span class="s">&quot;x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #E0E0E0, stop: 1 #FFFFFF); &quot;</span><span class="p">)</span>

    <span class="n">v</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QVBoxLayout</span><span class="p">()</span>
    <span class="n">v</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="p">)</span>
    <span class="n">searchGroup</span><span class="o">.</span><span class="n">setLayout</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>

    <span class="c"># Dialog standard buttons</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">buttonBox</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QDialogButtonBox</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">buttonBox</span><span class="o">.</span><span class="n">setOrientation</span><span class="p">(</span><span class="n">Qt</span><span class="o">.</span><span class="n">Horizontal</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">buttonBox</span><span class="o">.</span><span class="n">setStandardButtons</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QDialogButtonBox</span><span class="o">.</span><span class="n">Cancel</span><span class="o">|</span>
      <span class="n">QtGui</span><span class="o">.</span><span class="n">QDialogButtonBox</span><span class="o">.</span><span class="n">Ok</span><span class="p">)</span>

    <span class="c"># Layout                </span>
    <span class="n">layout</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QVBoxLayout</span><span class="p">()</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">addLayout</span><span class="p">(</span><span class="n">currentProj</span><span class="p">)</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="p">)</span>
    <span class="c">#layout.addWidget(self.searchWidget)</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="n">searchGroup</span><span class="p">)</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">buttonBox</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setLayout</span><span class="p">(</span><span class="n">layout</span><span class="p">)</span>

    <span class="c"># SIGNAL</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">onCurrentChanged</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">buttonBox</span><span class="o">.</span><span class="n">accepted</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">accept</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">buttonBox</span><span class="o">.</span><span class="n">rejected</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reject</span><span class="p">)</span>

    <span class="c"># Start search as if button was pressed</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">exact</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
      <span class="c"># Found! Clear search field and button</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="o">.</span><span class="n">resetBtnText</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">dlg</span> <span class="o">=</span> <span class="n">SaveEPSGDialog</span><span class="p">(</span><span class="n">proj</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
      <span class="k">if</span> <span class="n">dlg</span><span class="o">.</span><span class="n">exec_</span><span class="p">():</span>
        <span class="n">customProjStr</span><span class="p">,</span> <span class="n">epsgString</span> <span class="o">=</span> <span class="n">dlg</span><span class="o">.</span><span class="n">text</span><span class="p">()</span>
        <span class="n">newIndex</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">addCustom</span><span class="p">(</span><span class="n">customProjStr</span><span class="p">,</span> <span class="n">epsgString</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">customAdded</span><span class="p">(</span><span class="n">newIndex</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ProjDialog.keyPressEvent"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.ProjDialog.keyPressEvent">[docs]</a>  <span class="k">def</span> <span class="nf">keyPressEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Reimplementation of keyPressEvent to disable default behaviour</span>
<span class="sd">        of Return key (i.e. trigger the Ok button).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span><span class="p">()</span> <span class="o">==</span> <span class="n">Qt</span><span class="o">.</span><span class="n">Key_Escape</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">reject</span><span class="p">()</span>
    <span class="k">elif</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span><span class="p">()</span> <span class="o">==</span> <span class="n">Qt</span><span class="o">.</span><span class="n">Key_Enter</span> <span class="ow">or</span> <span class="n">event</span><span class="o">.</span><span class="n">key</span><span class="p">()</span> <span class="o">==</span> <span class="n">Qt</span><span class="o">.</span><span class="n">Key_Return</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">search</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="nb">super</span><span class="p">(</span><span class="n">ProjDialog</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">keyPressEvent</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ProjDialog.updateCurrent"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.ProjDialog.updateCurrent">[docs]</a>  <span class="k">def</span> <span class="nf">updateCurrent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Update current projection string</span>

<span class="sd">      :param text: new text</span>
<span class="sd">      :type text: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">text</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ProjDialog.onCurrentChanged"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.ProjDialog.onCurrentChanged">[docs]</a>  <span class="k">def</span> <span class="nf">onCurrentChanged</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">curIdx</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">preIdx</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">currentIndex</span><span class="p">()</span><span class="o">.</span><span class="n">internalPointer</span><span class="p">()</span>
    <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">isBranch</span><span class="p">():</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">updateCurrent</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">updateCurrent</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">projStr</span><span class="p">())</span>
</div>
<div class="viewcode-block" id="ProjDialog.search"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.ProjDialog.search">[docs]</a>  <span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Search projection string in tree</span>

<span class="sd">      :param exact: if False search also substrings</span>
<span class="sd">      :type exact: bool</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c"># Get the projection from the editor</span>
    <span class="n">projStr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="o">.</span><span class="n">text</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">projStr</span> <span class="o">==</span> <span class="s">&#39;&#39;</span><span class="p">:</span>
      <span class="c"># We don&#39;t search anything</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="o">.</span><span class="n">resetBtnText</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">clearSelection</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">collapseAll</span><span class="p">()</span>
      <span class="k">return</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="k">if</span> <span class="n">projStr</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">foundProjStr</span><span class="p">:</span>
        <span class="c"># New Search</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">foundList</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="c"># Reset text</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="o">.</span><span class="n">resetBtnText</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">foundList</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">model</span><span class="p">()</span><span class="o">.</span><span class="n">search</span><span class="p">(</span>
          <span class="nb">str</span><span class="p">(</span><span class="n">projStr</span><span class="p">),</span> <span class="n">matchCase</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">exact</span><span class="o">=</span><span class="n">exact</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">foundList</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
          <span class="c"># found!</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">foundProjStr</span> <span class="o">=</span> <span class="n">projStr</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">foundIndex</span> <span class="o">=</span> <span class="mi">0</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">foundIndex</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">foundIndex</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">foundList</span><span class="p">):</span>
          <span class="bp">self</span><span class="o">.</span><span class="n">foundIndex</span> <span class="o">=</span> <span class="mi">0</span>

      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">foundList</span><span class="p">:</span>
        <span class="n">howmany</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">foundList</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">howmany</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
          <span class="n">msg</span> <span class="o">=</span> <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span> <span class="s">&quot;1 of 1&quot;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
          <span class="n">msg</span> <span class="o">=</span> <span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;ProjDialog&quot;</span><span class="p">,</span> <span class="s">&quot;Move to </span><span class="si">%s</span><span class="s"> of </span><span class="si">%s</span><span class="s">&quot;</span><span class="p">)</span> <span class="o">%</span>
            <span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">foundIndex</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">%</span> <span class="n">howmany</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
            <span class="n">howmany</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="o">.</span><span class="n">setBtnText</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
        <span class="n">idx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">foundList</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">foundIndex</span><span class="p">]</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">setCurrentIndex</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">model</span><span class="p">()</span><span class="o">.</span><span class="n">indexOfCol0</span><span class="p">(</span><span class="n">idx</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">resizeView</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">True</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="k">return</span> <span class="bp">False</span>
</div>
<div class="viewcode-block" id="ProjDialog.projection"><a class="viewcode-back" href="../../ccqw.html#ccqw.projDialog.ProjDialog.projection">[docs]</a>  <span class="k">def</span> <span class="nf">projection</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return current projection string</span>

<span class="sd">      :returns: current projection string</span>
<span class="sd">      :rtype: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">currentProjLabel</span><span class="o">.</span><span class="n">text</span><span class="p">())</span>
</div>
  <span class="k">def</span> <span class="nf">_showSelection</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Show selected item proj4 string</span>

<span class="sd">      :param index: ???</span>
<span class="sd">      :type index: ???</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">index</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">currentIndex</span><span class="p">()</span>
    <span class="n">item</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">tree</span><span class="o">.</span><span class="n">model</span><span class="p">()</span><span class="o">.</span><span class="n">nodeFromIndex</span><span class="p">(</span><span class="n">index</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">item</span><span class="o">.</span><span class="n">isLeaf</span><span class="p">():</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">searchWidget</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">projStr</span><span class="p">())</span>

<span class="c">#===============================================================================</span></div>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span>

  <span class="kn">import</span> <span class="nn">signal</span>
  <span class="n">signal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="n">signal</span><span class="o">.</span><span class="n">SIGINT</span><span class="p">,</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIG_DFL</span><span class="p">)</span>

  <span class="n">app</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QApplication</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span>
  <span class="n">form</span> <span class="o">=</span> <span class="n">ProjDialog</span><span class="p">()</span>
  <span class="n">form</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="mi">640</span><span class="p">,</span> <span class="mi">480</span><span class="p">)</span>
  <span class="k">if</span> <span class="n">form</span><span class="o">.</span><span class="n">exec_</span><span class="p">():</span>
    <span class="k">print</span> <span class="n">form</span><span class="o">.</span><span class="n">projection</span><span class="p">()</span>
  <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">exec_</span><span class="p">())</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/ogs.png" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Roberto Vidmar, Nicola Creati.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>